package lk.service;

import lk.dao.BookDao;
import lk.pojo.Book;
import lk.pojo.BookCollection;
import lk.pojo.BookComment;
import lk.pojo.BookPraise;
import lk.util.SessionUtil;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
 * ClassName:BookServiceImpl
 * Description:
 */
@Service
public class BookServiceImpl implements BookService {

    @Resource
    private BookDao bookDao;

    @Override
    public int addBook(Book book) {
        return bookDao.addBook(book);
    }

    @Override
    public int examineBook(Long bookId) {
        return bookDao.examineBook(bookId);
    }

    @Override
    public int removeBook(Long bookId) {
        Book book = new Book();
        book.setBookId(bookId);
        book.setCreateBy(SessionUtil.getUserId());
        List<Book> list = bookDao.findMyBook(book);
        if (list != null && list.size() > 0) {
            return bookDao.removeBook(bookId);
        }
        return 0;
    }

    @Override
    public List<Book> findList(Book book) {
        return bookDao.findList(book);
    }

    @Override
    public List<Book> findMyBook(Book book) {
        return bookDao.findMyBook(book);
    }

    @Override
    public int bookcollection(BookCollection bookCollection) {
        List<BookCollection> list = bookDao.findBookCollection(bookCollection);
        if (list != null && list.size() > 0) {
            return 0;
        } else {
            return bookDao.bookcollection(bookCollection);
        }
    }

    @Override
    public List<BookCollection> findBookCollection(BookCollection bookCollection) {
        return bookDao.findBookCollection(bookCollection);
    }

    @Override
    public int removeBookcollection(BookCollection bookCollection) {
        return bookDao.removeBookcollection(bookCollection);
    }

    @Override
    public List<BookComment> findBookComment(Long bookId) {
        return bookDao.findBookComment(bookId);
    }

    @Override
    public int addBookComment(BookComment bookComment) {
        return bookDao.addBookComment(bookComment);
    }

    @Override
    public int removeBookComment(BookComment bookComment) {
        return bookDao.removeBookComment(bookComment);
    }

    @Override
    public int addBookPraise(BookPraise bookPraise) {
        List<BookPraise> list = bookDao.findBookPraise(bookPraise);
        if (list != null && list.size() > 0) {
            return 0;
        }
        return bookDao.addBookPraise(bookPraise);
    }

}
